﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ElfTyping.General;
using ElfTyping.Animations;
using ElfTyping.States.GameState.PlayerSpells;
using ElfTyping.States.GameState.PlayerPassives;

namespace ElfTyping.States.GameState.Entities
{
    public class Player : HealthEntity
    {
        public int ExperienceEarned { get; private set; }
        public int GoldEarned { get; private set; }
        public int PuzzlePiecesEarned { get; private set; }

        public int BaseDamage { get; private set; }
        public int TotalDamage { get { return BaseDamage; } }

        public List<PlayerSpell> Spells { get; private set; }
        public List<PlayerPassive> Passives { get; private set; }
        

        public Player(GameScript script, Vector2 centerPosition)
            : base(script, centerPosition)
        {
            PlayerStatus status = PlayerStatus.GetStatus();
            Equipment equipment = status.CurrentEquipment;

            ExperienceEarned = 0;
            PuzzlePiecesEarned = 0;
            BaseDamage = status.Strength;
            if (equipment.Arrow != null)
            {
                BaseDamage += equipment.Arrow.Damage;
            }
            MaximumHealth = status.MaximumHealth;
            CurrentAnimation = new FireEmblemNormalStanceAnimation(@"Textures\GameState\Archer_Blue");
            CurrentAnimation.SetAnimateOnce();
            CurrentAnimation.SetToEnd();
            CurrentAnimation.FrameTime = 0.25f;

            Spells = new List<PlayerSpell>();
            if (equipment.Spell1 != null)
            {
                Spells.Add(equipment.Spell1.Spell);
            }
            if (equipment.Spell2 != null)
            {
                Spells.Add(equipment.Spell2.Spell);
            }
            Passives = new List<PlayerPassive>();
            if (equipment.Passive1 != null)
            {
                Passives.Add(equipment.Passive1.PlayerPassive);
            }
            if (equipment.Passive2 != null)
            {
                Passives.Add(equipment.Passive2.PlayerPassive);
            }
        }

        public void GainExperience(int experienceGain)
        {
            ExperienceEarned += experienceGain;
        }

        public void GainPuzzlePiece()
        {
            PuzzlePiecesEarned += 1;
        }

        public void GainGold(int goldGain)
        {
            GoldEarned += goldGain;
        }

        public void Shoot()
        {
            CurrentAnimation.Reset();
        }        
    }
}
